package com.spzx.product.api;

import com.spzx.common.core.constant.SecurityConstants;
import com.spzx.common.core.constant.ServiceNameConstants;
import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.api.domain.Product;
import com.spzx.product.api.domain.ProductDetails;
import com.spzx.product.api.domain.ProductSku;
import com.spzx.product.api.domain.SkuLockVo;
import com.spzx.product.api.domain.vo.SkuPrice;
import com.spzx.product.api.domain.vo.SkuQuery;
import com.spzx.product.api.domain.vo.SkuStockVo;
import com.spzx.product.api.factory.RemoteProductFallbackFactory;


import io.swagger.v3.oas.annotations.Operation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 畅销商品 openFile接口
 */
@FeignClient(contextId = "remoteProductService" ,value = ServiceNameConstants.PRODUCT_SERVICE,
            fallbackFactory = RemoteProductFallbackFactory.class)
public interface RemoteProductService {

    //查询畅销的商品
    @GetMapping("/product/getTopSale")
    public R<List<ProductSku>> getTopSale(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);


    /**
     * 分页条件查询商品信息
     * @param pageNum 当前页
     * @param pageSize 每页记录数
     * @param skuQuery 查询对象
     * @return 返回多个对象
     */
    @GetMapping("/product/skuList/{pageNum}/{pageSize}")
    public R<TableDataInfo> skuList(
            @PathVariable(name = "pageNum") Integer pageNum,
            @PathVariable(name = "pageSize") Integer pageSize,
            /**
             * SpringQueryMap将 HTTP 请求的主体（body）映射为 Java 对象  和@RequestBoby相似
             * 一个用于Get请求 一个用于Post或者Put请求
             */
            @SpringQueryMap SkuQuery skuQuery,
            @RequestHeader(SecurityConstants.FROM_SOURCE) String source
    );


    //1.查询商品 product信息 productId
    @GetMapping("/product/getProduct/{id}")
    public R<Product> getProduct(@PathVariable("id") Long id, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    //2.查询productSku信息 skuId
    @GetMapping("/product/getProductSku/{skuId}")
    public R<ProductSku> getProductSku(@PathVariable("skuId") Long skuId ,@RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    //3.查询sku价格表 skuId
    @GetMapping("/product/getSkuPrice/{skuId}")
    public R<SkuPrice> getSkuPrice(@PathVariable("skuId") Long skuId ,@RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    //4.查询product_details表的url图片地址
    @GetMapping("/product/getProductDetails/{id}")
    public R<ProductDetails> getProductDetails(@PathVariable("id") Long id , @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    //5.skuStockVo信息
    @GetMapping("/product/getSkuStock/{skuId}")
    public R<SkuStockVo> getSkuStock(@PathVariable("skuId") Long skuId ,@RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    //6.skuSpecValueMap信息skuId
    //以map集合来接收 key为sku表的sku_spc  值为sku的主键id
    @GetMapping("/product/getSkuSpecValue/{id}")
    public R<Map<String,Long>> getSkuSpecValue(@PathVariable("id") Long id ,@RequestHeader(SecurityConstants.FROM_SOURCE) String source);



    //批量查询购物车的价格 之前6个接口之一的单个skuId--远程
    @PostMapping(value = "/product/getSkuPriceList")
    public R<List<SkuPrice>> getSkuPriceList(@RequestBody List<Long> skuIdList,@RequestHeader(SecurityConstants.FROM_SOURCE)String source);


    //检查库存是否够  够锁库存
    @PostMapping("/product/checkAndLock/{orderNo}")
    public R<String> checkAndLock(@PathVariable("orderNo") String orderNo, @RequestBody List<SkuLockVo> skuLockVoList ,@RequestHeader(SecurityConstants.FROM_SOURCE)String source);

}
